<template>
	<div>
		<van-nav-bar
		  title="栎搜"
		  left-text="返回"
		  left-arrow
		  @click-left="$router.go(-1)"
		 
		/>
		<van-search
		    v-model="value"
		    show-action
		    placeholder="请输入搜索关键词"
		    @search="onSearch"
		    @cancel="onCancel"
		  />
		  <div v-if='list.length>0'>
		  <div  v-for="(item,index) in list" :key='item.id'>
		  	<van-card
		  	  @click='toDetail(item)'
		  	  :price="item.price+'W'"
		  	  :title="item.content"
		  	  :thumb="item.img[0]"
		  	  :tag='JSON.stringify(item.start)'
		  	>
		  	<span slot='num'>{{item.last}}万公里</span>
			
		  	</van-card>
			
			</div>
			</div>
			<van-cell v-else title="空无一人,换个车试试"></van-cell>
	</div>
</template>

<script>
	
	export default {
		data(){
			return{
				value:'',
				allGoods:[],
				list:[]
			}
		},
		components:{
			
		},
		methods:{
			onSearch(){
				var _this = this;
				this.allGoods.forEach(val=>{
					val.forEach(it=>{
						if(it.content.indexOf(this.value)){
							_this.list.push(it);
						}
					})
				})
			},
			onCancel(){
				this.list = [];
				this.$toast('栎搜随时准备发车')
			},
			toDetail(item){
				localStorage.setItem('goods',JSON.stringify(item))
				this.$router.push({path:'/detail'});
			}
		},
		created() {
			this.allGoods = this.$api.goodsData;
			this.value = this.$route.query.key;
			this.onSearch();
		}
	}
</script>

<style>
</style>
